<?php
//use \LaneWeChat\Core\WeChatOAuth;
//include('../wechat/lanewechat.php');
//
//if (!isset($_GET['code']))
//{
//    WeChatOAuth::getCode('http://'.$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'],$_GET['ordernum']);
//}
//if (isset($_GET['code']) && !empty($_GET['code'])) {
//    $json = WeChatOAuth::getAccessTokenAndOpenId($_GET['code']);
//    if ($json['errcode']) {
//        header('location:error_weixin.html?msg=' . urlencode('获取用户身份出错'.$json['errcode']));
//        exit;
//    }
//    $sql_get_pid = "SELECT fid FROM uu_wx_member_pft WHERE fromusername='{$json['openid']}' LIMIT 1";
//    $stmt = \LaneWeChat\Core\Db::Connect()->prepare($sql_get_pid);
//    $stmt->execute();
//    $memberID_Bind = $stmt->fetchColumn(0);
//    if (!$memberID_Bind) {
//        header('location:error_weixin.html?msg=' . urlencode('您的微信账号还没有绑定平台账户，请先完成绑定'));
//        exit;
//    }
//}
include '/var/www/html/new/com.inc.php';
//订单查看
include  '/var/www/html/new/d/class/OrderRecord.php';
include  '/var/www/html/new/d/class/ProOrder.php';
include  '/var/www/html/new/d/class/SoapInit.class.php';
$fromt = isset($_GET['fromt']) ? $_GET['fromt'] : false;
//下单成功后发送微信通知，订单查看标识。
if ($fromt != 'f542e9fac6e76f4b3b66422d49e5585c') {
    if (!$_SESSION['memberID'])  {
        exit('登录超时或未登录，请重新<a href="login.html">登录</a>');
    }
}
$memberID   = isset($_SESSION['sid']) ? $_SESSION['memberID']
    : $_SESSION['sid'];
$soap = SoapInit::GetSoapInside();
$ordernum   = trim($_REQUEST['ordernum'])!='' ? trim($_REQUEST['ordernum']) : trim($_GET['state']);
if (!is_numeric($ordernum)) {
    exit('请求参数出错');
}
$or         = new OrderRecord($ordernum, $soap);
//$mporder    = new ProOrder($memberID, $soap);
$ifpack     = 1;
$concat_id  = 0;
//TODO::复票订单（联票）
if (isset($_GET['pack']) && $_GET['pack']==1 && $_GET['type']!='F') {
    $ifpack = 0;
    $concat_id = 1;
}
$orderInfo=$or->info($ifpack, $concat_id);
echo '<pre>';
print_r($_SESSION);

echo '</pre>';
$orders = array();
$title_sub = '产品信息';
if ($_GET['type']=='F') {
    $orders = $orderInfo['childOrder'];
    $title_sub = '套票信息';
}
else {
    $orders=array(0=>$orderInfo['mainOrder']);
    $orders=array_merge($orders,$orderInfo['childOrder']);
}
//开心假期要显示手机号
$apply_did = '21268';
$sql = "select id from uu_land where apply_did in ($apply_did)";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
    $lids[] = $row['id'];
}
if(!in_array((int)$orderInfo['mainOrder']->UUlid,$lids)){
    if($orderInfo['mainOrder']->UUmid!=$memberID && $_SESSION['dtype']!=5 ) {
        if($orderInfo['mainOrder']->UUstatus!=1){
            $orderInfo['mainOrder']->UUordertel=substr_replace((string)$orderInfo['mainOrder']->UUordertel,"****",3,4);
        }
    }
}
//echo $s->reSend_SMS_Global_PL('100011',4,3)//最后重发短信
$totalMoney = 0;
$_aids = array($orderInfo['mainOrder']->UUaid);
if($orderInfo['mainOrder']->UUaids){
    $_aids[] = explode(",",$orderInfo['mainOrder']->UUaids);
    $dname=array();
    $totalMoney = $orderInfo['mainOrder']->UUtnum * $orderInfo['mainOrder']->UUtprice;
}

//订单权限判断
if ($_SESSION['dtype']!=9
    && !in_array($memberID, $_aids)
    && $orderInfo['mainOrder']->UUsellid!=$memberID
    && $orderInfo['mainOrder']->UUbuyid!=$memberID
    && $orderInfo['mainOrder']->UUmid != $memberID
) {
    if($_SESSION['dtype']==5
        && $orderInfo['mainOrder']->UUcontacttel !=$_SESSION['account'] )
    {
        exit('您无权限查看此订单');
    }
//    exit('您无权限查看此订单');
}

if(count($orders)>0){
    $ordernums = array();
    foreach($orders as $key=> $cur){
        $ordernums[] = (string)$cur->UUordernum;
        if($key==0) continue;
        $totalMoney = $totalMoney+((string)$cur->UUtnum * (string)$cur->UUtprice);
    }
}
$hidePrice = false;
//
if($orderInfo['mainOrder']->UUp_type=='F'){
    $hidePrice = true;
    $totalMoney = $orderInfo['totalPrice'][0];
}
$udata = array();
if(!empty($ordernums)){
    $sql="select * from pft_order_num_modify where orderid in (".implode(',',$ordernums).") order by id asc";
    $GLOBALS['le']->query($sql);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $udata[$row['orderid']][] = $row;
    }
}

if ($orderInfo['mainOrder']->UUpaystatus==1 || $orderInfo['mainOrder']->UUpaystatus==0) {
    $qrcode = strval($orderInfo['mainOrder']->UUcode);
}


?>
<? include('header.html') ?>
<title>订单详情</title>
<link type="text/css" rel="stylesheet" href="../public/css/order_detail.css?timestamp=<?=time();?>" />
<script type="text/javascript" src="../public/js/modernizr.js"></script>
</head>
<body>
<div id="fixedHead" class="fixedHead">
    <p class="con"><?=$orderInfo['mainOrder']->UUltitle?></p>
    <button id="" class="fixedGoBack" ontouchend="javascript:history.go(-1)"><i class="fa fa-chevron-left"></i></button>
    <button id="" class="fixMoreBtn"><i class="io"></i><i class="io"></i><i class="io"></i></button>
</div>
<div id="detailInfoWrap" class="content">
    <div class="dzwrap">
        <?php if(isset($qrcode)):?>
        <div class="emaWrap">
            <span class="imgW">
                <img src="http://api.k780.com:88/?app=qr.get&data=<?=$qrcode?>&level=H&size=8" alt=""/>
            </span>
            <p class="t">对准窗口刷码验证</p>
        </div>
        <?php endif;?>
        <h3 id="topTit" class="topTit"><?=$orderInfo['mainOrder']->UUltitle?></h3>
        <div class="box">
            <h5>订单信息</h5>
            <ul class="con">
                <li><span class="lt">订单号</span><span class="rig"><?=$orderInfo['mainOrder']->UUordernum;?></span></li>
                <li><span class="lt">有效期限</span><span class="rig"><?=$orderInfo['mainOrder']->UUendtime;?></span></li>
                <li><span class="lt">总金额</span><span class="rig"><em class="totalMoney"><?=$totalMoney / 100?></em><i>元</i></span></li>
                <li><span class="lt">联系人</span><span class="rig"><?=$orderInfo['mainOrder']->UUordername;?></span></li>
                <li><span class="lt">手机号</span><span class="rig"><?=$orderInfo['mainOrder']->UUordertel;?></span></li>
                <li><span class="lt">订单状态</span><span class="rig">
                    <?if((string)$orderInfo['mainOrder']->UUpmode==1 && (string)$orderInfo['mainOrder']->UUpaystatus==2):?>
                    <?=OrderRecord::$paystatusT[(string)$orderInfo['mainOrder']->UUpaystatus]?>
                    <?else:?>
                    <!--套票子票有一张使用则显示套票已使用-->
                    <?if((string)$orderInfo['mainOrder']->UUp_type=='F' && (string)$orderInfo['mainOrder']->UUstatus==7):?>
                    <?=OrderRecord::$UUstatusT[1]?>
                    <?else:?>
                    <?=OrderRecord::$UUstatusT[(string)$orderInfo['mainOrder']->UUstatus]?>
                                    <!--//套票子票有一张使用则显示套票已使用-->
                    <?endif;?>
                    <?endif;?>
                </span></li>
                <li><span class="lt">下单时间</span><span class="rig"><?=$orderInfo['mainOrder']->UUordertime;?></span></li>
                <li><span class="lt">预计游玩</span><span class="rig"><?=$orderInfo['mainOrder']->UUbegintime;?></span></li>
            </ul>
        </div>
         <div class="box prodMesgBox">
            <h5>产品信息</h5>
            <ul class="con">
                <table><tbody>
                     <?php foreach($orders as $order):?>
                        <tr>
                            <td class="tname col">
                                <?=$order->UUltitle?>-
                                <?=$order->UUttitle?>
                                <?//=OrderRecord::$UUstatusT[(string)$row->UUstatus]?>
                            </td>
                            <td class="count col orange"><span class="star">*</span><em class="num"><?=$order->UUtnum?></em><i class="zhang">张</i></td>
                            <?php if(!$hidePrice):?>
                            <td class="count col orange"><span class="star">*</span><span class="yen">&yen;</span><em class="num"><?=(int)$order->UUtprice/100?></em></td>
                             <?php endif;?>
                        </tr>
                        <?php endforeach;?>
                </tbody></table>
            </ul>
        </div>
        <div class="box">
            <h5>取票地点</h5>
            <ul class="con">
                <li class="getaddr"><?=$orderInfo['mainOrder']->UUgetaddr;?></li>
            </ul>
        </div>
    </div>
</div>
<? include('footer.html');?>
</body>